#!/bin/sh

# get time from RTC
i2c-rtc --sync -r 0

cd /access_node/firmware

if [ -f common.sh ]; then
	. common.sh
	VerifyConsistentHwVer || exit 1
fi

# log this after get time
log2flash "***** AN POWER ON: uptime=`cat /proc/uptime | cut -f1 -d ' '`s"

[ -f /access_node/etc/cp_without_ids ] && set_usb_ttys.sh

#sudden reboot troubleshoot - START
echo 1 > /proc/sys/vm/oom_dump_tasks
echo 1 > /proc/sys/vm/oom_kill_allocating_task
echo 1 > /proc/sys/vm/overcommit_ratio
echo 0 > /proc/sys/vm/overcommit_memory
echo "256 1" > /proc/sys/vm/lowmem_reserve_ratio
echo 2048 > /proc/sys/vm/min_free_kbytes
echo 100  > /proc/sys/vm/max_map_count
#sudden reboot troubleshoot - END

# Tell the kernel we have no swap
# 0-100: The higher a number set here, the more the system will swap.
echo 0 > /proc/sys/vm/swappiness

#conf Ipv4 TCP timeouts
echo 5  > /proc/sys/net/ipv4/tcp_keepalive_time
echo 10 > /proc/sys/net/ipv4/tcp_keepalive_intvl
echo 9  > /proc/sys/net/ipv4/tcp_keepalive_probes
echo 11 > /proc/sys/net/ipv4/tcp_retries2

[ -f /etc/config/vpn_client ] && openvpn --config /access_node/activity_files/openvpn/client.config --script-security 2 &

#temporary fix until we have i2c
#TODO: REMOVE
ntpadjust.sh affect_ntpd
sleep 5

echo "---DATE---"
date	# log current date, to see on serial log
echo ""


if [ -f start.sh ]; then
	start.sh no_stop
	echo "Starting discovery&"
	/access_node/firmware/discovery&
	echo "---DATE---"
	date
else
	echo "PANIC Nivis apps NOT found, nothing to run..."
	echo "Starting a shell just for debugging."
	echo "Do not forget to reboot afterwards."
	/bin/sh;
fi
